import {
  getTodayTests as getTodayTestsUrl,
  submitTest as submitTestUrl,
  completedTodayTests as completedTodayTestsUrl,
  allCompletedTests as allCompletedTestsUrl
} from "../apis/index";
import { request } from "./http-base";
import { TodayHealthyTest } from "../types/health-test";

// 获取测验题目每日2题
export const getTodayTests = async (): Promise<TodayHealthyTest[]> => {
  const res = await request(getTodayTestsUrl);
  return res?.data?.data || [];
};

interface SubmitTestParams {
  healthTestId: number;
  optionId: number;
}
// 提交测验结果
export const submitTest = async (params: SubmitTestParams) => {
  return await request(
    `${submitTestUrl}/?healthTestId=${params.healthTestId}&optionId=${params.optionId}`,
    {},
    "POST"
  );
};

// 查看是否有完成当日测验
export const completedTodayTests = () => request(`${completedTodayTestsUrl}`);

// 查看是否有完成所有测验
export const allCompletedTests = () => request(`${allCompletedTestsUrl}`);
